﻿using Microsoft.AspNetCore.Authorization;
using System.Threading.Tasks;

namespace Rechargeable.Web.Pages
{
    public class IndexModel : RechargeablePageModel
    {
        IAuthorizationService _authorizationService;

        public IndexModel(IAuthorizationService authorizationService)
        {
            _authorizationService = authorizationService;
        }


        public async Task OnGet()
        {
            if (await _authorizationService.IsGrantedAsync(Amazon.Permissions.AmazonPermissions.Products))
            {
                Response.Redirect("Amazon");
                return;
            }
            if (CurrentUser.IsAuthenticated)
                Response.Redirect("/Machines");
        }
    }
}